<?php
/** @var SmsController $this */
/** @var Sms $model */
Util::tsRegisterAssetJs('historial_ganancias.js');
//Util::tsRegisterAssetJs('sms.js');
$this->menu = array(
    array(
        'label' => 'Exportar', 'icon' => 'download-alt', 'url' => '#', 'items' => array(
            array('label' => 'Todos', 'url' => '#', 'linkOptions' => array(
                    'onclick' => 'ExportFactura(true, $("#search_value").val())',),),
            array('label' => 'Seleccionados', 'url' => '#', 'linkOptions' => array(
                    'onclick' => 'ExportFactura(false, "")',),)
        ),
    ),
);
?>
<div class="widget blue">
    <div class="widget-title">
        <h4><i class="icon-comments"></i><?php echo 'Historial de  Ganancias' ?> </h4>
    </div>
    <div class="widget-body">

        <div class="control-label required span1">Filtro <span class="required">*</span></div>
        <div class="search-form">
            <?php
            $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
                'action' => Yii::app()->createUrl("historial"),
                'method' => 'get',
            ));
            ?>

            <?php
            $this->widget('ext.bootstrap.widgets.TbDateRangePicker', array(
                'name' => 'search[value]',
//                'model' => $model,
//                'attribute' => 'fechas',
                'options' => array(
                    'format' => 'dd-MM-yyyy',
                    'ranges' => array(
                        'Hoy' => array('today', 'today'),
                        'Ayer' => array('yesterday', 'yesterday'),
                        'Semana actual' => array('monday', 'today'),
                        'Semana Anterior' => array(Util::calcularSemanaAnterior(0), Util::calcularSemanaAnterior(1)),
                        'Mes Actual' => array(Util::obtenerPrimerDiaMes(), Util::obtenerUltimoDiaMes()),
                        'Mes Anterior' => array(Util::calcularMesAnterior(0), Util::calcularMesAnterior(1)),
                    )
                ),
                'callback' => 'js:function(){search()}',
                'htmlOptions' => array(
                    'readonly' => true,
                    'class' => "search_value"
                ),
            ));
            ?>
            <?php $this->endWidget(); ?>
        </div>
        <?php
        $this->widget('ext.selgridview.BootSelGridView', array(
            'id' => 'pedido-grid',
            'type' => 'striped bordered hover advance',
            'selectableRows' => 2,
            'dataProvider' => $model->ordenDescendente()->searchGanancias(),
            'columns' => array(
                array(
                    'name' => 'id_pedido',
                    'id' => 'check',
                    'class' => 'CCheckBoxColumn',
                    'value' => '$data->id',
                ),
//                'id',
//                'numero',
//                'estado',
                array(
                    'header' => 'Empleado',
                    'value' => '$data->empleado->nombre_completo',
                ),
                'fecha',
                array(
                    'header' => 'Ticket',
                    'value' => '$data->ticket->numero',
                ),
                array(
                    'header' => 'Valor total',
                    'value' => '$data->valor_total',
                ),
                array(
                    'header' => 'Costo Total',
                    'value' => '$data->valor_total ?  number_format($data->obtenerPrecioCostoPedido(),2) : null',
                ),
                array(
                    'header' => 'Ganancia',
                    'value' => 'isset($data->valor_total) ? number_format(($data->valor_total - $data->obtenerPrecioCostoPedido()),2) : null',
                    'htmlOptions' => array('class' => 'gananciaMenu')
//            'filter' => CHtml::listData(MenuSeccion::model()->findAll(), 'id', MenuSeccion::representingColumn()),
                ),
//                array(
//            'header' => 'Costo',
//            'value' => 'isset($data->precio) ? number_format($data->obtenerPrecioCostoMenu(),2) : null',
////            'filter' => CHtml::listData(MenuSeccion::model()->findAll(), 'id', MenuSeccion::representingColumn()),
//        ),
            ),
        ));
        ?>

    </div>
</div>
<form id="formId" method="post" target="blank">
    <input type="hidden" id="id_factura" name="Factura">
</form>